This article describes the ASP.net StreamReader to create a file instance code, you need friends can refer to the
copy code code as follows:
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Text; using System.IO; A summary descr
Well, first of all, here's the picture:
Here is the official explanation of the Textreder: (http://msdn.microsoft.com/zh-cn/library/system.io.textreader.aspx)
Peek and Read methods to make a useful instance of TextReader. ">Here is the official explanation of the Stream class: (http://msdn.microsoft.com/zh-cn/library/system.io.stream.aspx)
Peek and Read methods to make a useful instance of TextReader. ">We want to use the FileStream and StreamReader
Today, I want to write a small tool to extract some text from a file,
Code As follows:
Public
Static
Void
Main (
String
[] ARGs)
{Streamreader SR = New Streamreader (ARGs [ 0 ], Encoding. Default, False , 1 );Sr. basestream. Seek ( Zero X 00005298 , Seekorigin. Begin ); String Line = Null ; Do {Line=Sr. Readline ();Console. writeline (line );} While (Sr. ba
In the process of writing a text file to read and write, you have the following codeStreamReader sr = new StreamReader (FileName);The results show that the text file is garbled in Chinese.
Take this StreamReader reader = new StreamReader (textfile, Encoding.default);Change intoStreamReader reader = new StreamReader (t
First, the structured parameters of the streamreader class are rich.
Here, I think the most common ones are streamreader (Stream stream) and streamreader (string Str ).
The first one can be directly put into a data stream, such as filestream, while the second one can be simply put into STR, such as "C:/test.txt"
It focuses on the use of its three methods.
the writetoend () that encapsulates the StreamReader class of ReadToEnd () and the StreamWriter class,The return values of both methods are of type string, so only text files can be read and writtenSmall text file single-line read-write with StreamReader and StreamWriter these two classesSmall non-text files are read and written using the file class's ReadAllBytes () and WriteAllBytes () and byte[] as a br
Thank you first! Turn from: http://blog.sina.com.cn/s/blog_67299aec0100snk4.html This may not be very deep, but it is clear that the FileStream object represents a stream that points to a file on a disk or network path. This class provides a way to read and write bytes in a file , but often uses StreamReader or StreamWriter to perform these functions. This is becauseThe FileStream class operates on byte and byte arrays, while the Stream class operates
6. Vote for the favorite
At first, I used StreamReader to read text from the file.Card Reader = new StreamReader ("dialog box. Use OpenFile ());TxtEditor. Text Reader. ReadToEnd ();However, I found that File. ReadAllText seems to simplify my code to line 1. But I think, if there are any differences between two? Or when should I use 1 more than others?TxtEditor. Text file. ReadAllText (dialog. FileName );
earlier to get the current file name:
Dim mike_pathname As String
Mike_pathname=mike_getfilename ()
Instantiates a read channel to the file, creating a FileStream object:
Mike_stream=new FileStream (Mike_pathname,filemode.openorcreate,fileaccess.read)
Prevents an exception that is the first time the page is accessed and the count file is created using OpenOrCreate.
The following uses the StreamReader object to read the file:
Mike_readobj=new
Extract originalCodePart
Streamreader sr = New System. Io. streamreader (stream, encoding ); // Sr. discardbuffereddata (); Int Totalcount = 0 ; Using (SR ){ Int Line = 0 ; While (Sr. Peek ()> 0 ){ ++ Line; String Temp = Sr. Readline ();
Stream is the uploaded file stream.
The file is in CSV format and I processed it in batches. A total of 20 thousand lines of files are pr
Write and write a text file
ProgramIn the process, there are the following
CodeStreamreader sr = new streamreader (filename); garbled characters are displayed when a Chinese text file is opened. The reason is that since Windows 2000 and later operating systems use Unicode by default during file processing, the default file encoding for. NET is also Unicode. Unless otherwise specified, streamreader is enco
At the beginning, I learned C # and wrote some simple console applications: Reading, processing, and writing files.
The concepts and usage of File, FileInfo, FileStream, and StreamReader are confusing all the time. I will summarize them today.
In summary, File, FileInfo, and FileStream are classes used for File I/O, and StreamReader is used to read and write streams from streams. before using them, you must
, FileMode.Create)) { byte[] data =Encoding.Default.GetBytes (content); FileStream.Write (data,0, data. Length);//write content to buffer//Flush () writes the buffer contents to the file system, which is automatically written to the file system when it is closed or out of use .//Filestream.flush (); //using a closed stream that does not have to be displayed, it automatically shuts down and releases//filestream.close ();}//Append Contentusing(FileStream FileStream =NewFileStream (path, filemod
Yesterday I made a software program for memorizing words, in which system. Io was used to read Word files. However, when streamreader sr = new streamreader (filename); is used, when Sr. Readline (); is output, all Chinese characters in the file are garbled. So I found a solution on the Internet and finally found the cause:Reference: (from yijiemei)******The reason is that since Windows 2000 and later operat
The FileStream object represents a stream that points to a file on a disk or network path. This class provides a way to read and write bytes in a file, but often uses StreamReader or StreamWriter to perform these functions. This is because the FileStream class operates on byte and byte arrays, and the Stream class operates on character data. Character data is easy to use, but some operations, such as random file access (accessing data at a point in th
In summary, File,fileinfo,filestream is the class used for file I/O, and StreamReader is the class used to read from and write to the stream, using System.IO before use.Define a TXT document path First: string Txtpath = (@ "d:\c# exercise \1.txt"); To read into this document.(1) File provides static methods for creating, copying, deleting, moving, and opening files, and assists in creating FileStream.FileStream fs = File.Open (Txtpath, FileMode.Open);
FileStream can manipulate any file.
FileStream can manipulate large files.
StreamReader and StreamWriter are only for text files, and text files are simpler to manipulate.
1 Private voidButton1_Click (Objectsender, EventArgs e)2 {3 //FileStream can read and write any file, SteamReader, Steamwriter is only suitable for reading and writing text files4 5 using(FileStream fs =NewFileStream ("Test.txt",
Read and write operations on the file should be the most important file operations, System.IO namespace for us to provide a number of file read and write operation classes, here I want to introduce the most common is the most basic StreamReader class and StreamWriter class. From the names of these two classes, it is not difficult to find that they are both stream-based read and write operations classes.We can get a
MyStreamMyStream. Flush ();//Refresh data in a streamMyStream. Close ();Three, memory flowThe MemoryStream class is primarily used to manipulate data in memory. For example, the transmission of data in the network can be in the form of streams, when we receive these streaming data can be declared MemoryStream class to store and process them.MemoryStream Action string: string str = " hi! Hello! ; byte [] array = Encoding.UTF8.GetBytes (str); // MemoryStream memory = new MemoryStream (arr
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.